package org.aeon.client.handler.Inbound;

import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import lombok.extern.slf4j.Slf4j;
import org.aeon.client.view.components.menuPanel.PopupPrompt;
import org.aeon.message.response.FriendApplyResponseMessage;


/**
 * @author: MissingAeon
 * @date: 2024/1/29 15:41
 * @description: 好友应用响应处理程序
 */
@Slf4j
@ChannelHandler.Sharable
public class FriendApplyResponseHandler extends SimpleChannelInboundHandler<FriendApplyResponseMessage> {

    @Override
    protected void channelRead0(ChannelHandlerContext ctx, FriendApplyResponseMessage msg) throws Exception {
        if (msg.getResponseID() == null) {
            // 其他用户信息
            PopupPrompt.createPopUp(String.format("%s(%s)发来好友请求", msg.getFrom().getNickname(), msg.getFrom().getUsername()));
        } else {
            // 服务器回应
            PopupPrompt.createPopUp(msg.getReason());
            ctx.fireChannelRead(msg);
        }
    }
}
